  <div id="edit_client" class="zoom-anim-dialog relative add-booking-popup">                       
                       <div class="view-booking-popup">
                        <h1>تعديل العقد / الحجز</h1>
                        <hr />
                        <form method="POST" action="editContract.php" name="editContract" id="editContract">
                        <div class="bookings-edit-container">
                        <span class="text-right small">   رقم العقد / الحجز : <?php echo $contract['contract_id']; ?> </span>
                        <h2>الفترة</h2>
                        <div class="bookings-edit-row">
                        <?php if($contract['contract_status'] == 3)
                                $disabled = "disabled";
                              else
                                $disabled = "";
                         ?>
                        <table class="edit-bookings-table add_bookings disabled-style" disabled="<?php echo $disabled; ?>">

                              <tr class="">
                                    <td width="100px">&nbsp;نوع الايجار</td>&nbsp;
                                    <td>
                                      <select name="rent_type" style="width:70px; margin-left:10px;" class="rent_type">
                                        <?php if( $contract['rent_type'] == 0 ) { ?>
                                          <option selected="selected"  value="0">يومى</option>
                                        <?php } else { ?>
                                         <option value="0">يومى</option>
                                        <?php } ?>
                                        <?php if( $contract['rent_type'] == 1 ) { ?>
                                          <option selected="selected"  value="1">إسبوعى</option>
                                        <?php } else { ?>
                                         <option value="1">إسبوعى</option>
                                        <?php } ?>
                                        <?php if( $contract['rent_type'] == 2 ) { ?>
                                          <option selected="selected"  value="2">شهرى</option>
                                        <?php } else { ?>
                                         <option value="2">شهرى</option>
                                        <?php } ?>
                                        <input type="hidden" value="0" class="requsting-page"  name="requsting-page"/> <!-- determine from where the submission came from-->
                                        <input type="hidden" value="-1" class="sendRecentContrat"  name="sendRecentContrat"/> <!-- opens recent contract given ID-->
                                      </select>                                    
                                    </td>
                                    <td>ميلادي</td>
                                    <td >من  </td>
                                    <td>
                                    <?php $from =  strtotime($contract['mildai_from']); ?>
                                    <?php $to =  strtotime($contract['miladi_out']); ?>
                                      <input type="hidden" name="contract_id" class="contract_id small-input " value="<?php echo $contract['contract_id'];?>"/>
                                      <input type="text" style="width:60px; margin-right:10px"  class="small-input check-today" name="from" id="from-miladi"  placeholder="" value="<?php echo date("Y-m-d",$from); ?>" />
                                    </td>
                                    <td style="width:30px;">إلى  :</td>
                                    <td style="width:50px;">
                                      <input type="text" style="width:60px; margin:0 10px" class="small-input " name="to"  id="to-miladi" placeholder="" value="<?php echo date("Y-m-d",$to); ?>" />
                                    </td>
                                    <td width="75px">عدد الأيام</td>
                                    <td><input type="text" class="xsmall-input period-days" name="period"  id="daily" value="<?php echo $contract['period']; ?>" /></td>
                                </tr>
                                <tr>
                                    <td>الموافق:</td>
                                    <td></td>
                                    <td>هجري</td>
                                    <td >من:</td>
                                    <td colspan="3">
                                      <div class="show-from-hijri-from"><?php echo $contract['hijri_in']; ?></div>
                                      <input type="hidden" value="<?php echo $contract['hijri_in']; ?>" name="hijri-from" id="show-from-hijri-from"/>
                                    </td>
                                    <td>عدد الأشهر</td>
                                    <td><input type="text" class="xsmall-input period-months" name="" id="monthly" value="<?php echo floor($contract['period']/30); ?>" /></td>
                                </tr>
                                
                                <tr>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td >إلى:</td>
                                    <td colspan="3">
                                      <div class="show-from-hijri-to"><?php echo $contract['hijri_out']; ?></div>
                                      <input type="hidden" value="<?php echo $contract['hijri_out']; ?>" name="hijri-to" id="show-from-hijri-to"/>
                                    </td>
                                    <td></td>
                                    <td></td>
                                </tr>
                         </table>       
                        </div>
                        <h2>الوحدة \ العميل </h2>
                        <div class="bookings-edit-row">
                        <table class="edit-bookings-table disabled-style" disabled="<?php echo $disabled; ?>" >
														<?php
								$pid=getpid($contract['mildai_from']);
								if ($pid==-1)
								{
								$md=0;
								}
								else
								{
								$md=getmd($contract['apartment_id'],$pid);
								}
								?>
                            	<tr>
                                    <td>الوحدة</td>
                                    <input type="hidden" name="apartment_id" id="apartment_id" value="<?php echo $contract['apartment_id']; ?>"/>
                                    <!-- Store latest chosen apartment prices -->
                                    <input type="hidden" name="weekly_price" id="weekly_price" value="<?php echo $contract['chosen_weekly']; ?>"/>
                                    <input type="hidden" name="daily_price" id="daily_price" value="<?php echo $contract['chosen_daily']; ?>"/>
                                    <input type="hidden"  name="monthly_price" id="monthly_price" value="<?php echo $contract['chosen_monthly']; ?>"/>
                                    <input type="hidden"  name="maxd" id="maxd" value="<?php echo $md; ?>"/>
                                    
                                    
                                    <td style="width:100px;" id="apartment-found"><?php echo $contract['apart_name']; ?></td>
                                    <input type="hidden" id="apartment_names" name="apart_name" value="<?php echo $contract['apart_name']; ?>"/>
                                    <!-- Choose Apartment pop-up triggerer, Ajax request will be sent to href url -->
                                    <td style="width:60px;"></td>
                                    <td class="client-selection">العميل</td>
                                    <td class="client-found client-selection"><?php echo $contract['name']; ?></td>
                                    <input type="hidden" name="client_id" id="client_id" value="<?php echo $contract['client_id']; ?>"/>
                                    <td>
                                    	<!--<a href="choose-pop-ups/choose_client.php" disabled="disabled" class="ajax-pop-up client-selection"><img src="images/magnifying.png" class="margin-right5" align="" title="إختار العميل"alt="Edit"/></a>
                                      <a href="createClientAjax.php" id="client_add" class="ajax-pop-up disabled-style-no-bg" disabled="disabled"><img src="images/plus.png" class="margin-right5" align="" title="إضافة عميل"alt="Edit"/></a> -->                     
                                    </td>
                                    
                                </tr>
                                <tr>
                                    <td>سعر الوحدة</td>
                                    <td id="apartment-price" style="border:none">
                                    <?php if( $contract['rent_type'] == 0 ) { 
                                      echo $contract['chosen_daily'];
                                    }
                                    else if( $contract['rent_type'] == 1 ){
                                      echo $contract['chosen_weekly'];
                                    }
                                    else
                                       echo $contract['chosen_monthly'];
                                    ?>
                                    </td>
                                    <td></td>
                                    
                                    <td class="company-selection" >الشركة</td>
                                    <td class="company-selection company-found" ><?php if(!empty($contract['related_company'])) {echo $contract['related_company'];}else{echo '...';} ?></td>
                                    <input type="hidden" name="company_id" id="company_id" value="<?php if(!empty($contract['related_company'])) {echo $contract['company_id'];} ?>"/>
                                    <input type="hidden" name="company_name" id="company_name" value="<?php if(!empty($contract['related_company'])) {echo $contract['related_company'];} ?>"/>
                                    <td class="company-selection" >
                                    	<div class="company-selection">
                                        <a href="#" class="delete-company"><img src="images/x.png" class="right margin-right5" align="" alt="Delete" title="حذف الشركة"/></a>
                                        <!--<a href="choose_company.php" class="ajax-pop-up"><img src="images/magnifying.png" class="margin-right5" align="" alt="Edit"/> -->
                                      </a>
                                        <!--<a href="#edit_client" class="edit_client_pop"><img src="images/plus.png" class="margin-right5" align="" alt="Edit"/></a>
                                        <a href="#edit_client" class="edit_client_pop"><img src="images/edit.png" class="margin-right5" align="" alt="Edit"/></a>
                                        <a href="#edit_client" class="edit_client_pop"><img src="images/x.png" class="margin-right5" align="" alt="Edit"/></a>
                                    </div>-->
                                    
                                    </td><td><p class="discount"><?php if(!empty($contract['co_discount'])) echo $contract['co_discount']; ?></p></td>
                                    
                                </tr>
                                
                               
                         </table>
<hr />
                         <table class="edit-bookings-table bookings-edit-row discount-control disabled-style" disabled="<?php echo $disabled; ?>" >
                            	<tr>
                                    <tr><td class="black max-discount-text" colspan="3">مبلغ الخصم المتاح: <span class="red"><?php echo $md;?></span> </td></tr>
                                    <td style="width:90px;">مبلغ الخصم</td>
                                    <td ><input type="text" class="get-discount small-input" name="discount"  value="<?php echo $contract['discount'] ?>"/></td>
                                    <td class="blue"></td>
                                    <td >التكلفة الكلية</td>
                                    <td class="total_price"><?php echo $contract['total']+ $contract['services_revenue'] ?></td>
                                </tr>
                                
                                <tr>
                                    <td>مبلغ الخصم الإضافى</td>
                                    <td style="width:168px;"><input type="text" class="get-fixed-discount small-input" name="fixed_discount" <?php if($_SESSION['r']>1){echo "disabled";} ?>  value="<?php echo $contract['fixed_discount'] ?>"/></td>
                                    <td></td>
                                    <td >التكلفة النهائية</td>
                                    <?php
                                      //price applied Discount
                                      $price_discounted = $contract['total'] - ( ( ($contract['discount'] + $contract['co_discount']) )  ) - $contract['fixed_discount'];
                                    ?>
                                    <td class="final_price"><?php echo $price_discounted + $contract['services_revenue']; ?></td>
                                    <input type="hidden" id="final_price" name="final-price" value="<?php echo $contract['total']; ?>"/>
                                </tr>
                                
                                <tr>
                                    <td></td>
                                    <td></td>
                                    <td class="blue"></td>
                                    <td>الرصيد</td>
                                    <?php if($contract['paid']-$contract['paid_back']- $price_discounted - $contract['services_revenue']>0)
                                            $class = "green";
                                          else if($contract['paid']-$contract['paid_back']- $price_discounted - $contract['services_revenue']<0)
                                            $class = "red";
                                          else
                                            $class = "black";
                                    ?>
                                    <td class="<?php echo $class; ?> credit"><?php echo $contract['paid']-$contract['paid_back']-$price_discounted- $contract['services_revenue']; ?></td>
                                </tr>
                         </table>  
						 <h2>ملاحظات</h2>
                        <div class="bookings-edit-row disabled-style" disabled="<?php echo $disabled; ?>" >
                        	<p align="right"><textarea name="notes"><?php if(!empty($contract['notes'])){echo $contract['notes']; } ?></textarea></p>
                        </div>
                         <div class="save-botton  disabled-style left" style="width:100px">حفظ</div> 
                         <div class="clear"></div>
                        </div>
                        <h2>المالية</h2>
                        <div class="bookings-edit-row">
                        <table class="edit-bookings-table disabled-style" disabled="<?php echo $disabled; ?>">
                            	<tr>
                                    <td>المقبوضات</td>
                                    <td>
                                      <select class="small-select recipets" name="recipets" >
                                        <?php 
                                          $recipets = query("SELECT * FROM recipt_vouchers where contract_id = ?",$contract['contract_id']);
                                          foreach($recipets as $recipet)
                                          {
                                            echo "<option value='{$recipet['recipet_id']}'>{$recipet['recipet_id']}# | {$recipet['amount']} ر.س</option>";
                                          }
                                        ?>
                                        
                                      </select>
                                    </td>
                                    <td>
                                    	<!--<a href="#edit_client<?php //echo $contract['contract_id']; ?>" class="edit_client_pop"><img src="images/print.png" class="margin-right5" align="" alt="Edit"/></a>-->
                                      <a href="#edit_client" class="print_reciet"><img src="images/print.png" class="margin-right5" align="" alt="Edit"/></a>
                                       <!-- create pop-up triggerer, Ajax request will be sent to href url -->
                                      <a href="create-pop-ups/reciept.php?id=<?php echo $contract['contract_id']; ?>" class="ajax-pop-ups-magnific-no-modal"><img src="images/plus.png" class="margin-right5" align="" alt="Edit"/></a>
                                      <!--<a href="#edit_client" class="edit_client_pop"><img src="images/magnifying.png" class="margin-right5" align="" alt="Edit"/></a>-->
                                    </td>
                                    <td  style="width:180px;">المقبوض</td>
                                    <td class="what_paid"><?php echo $contract['paid']; ?></td>
                                </tr>
                                
                                <tr>
                                    <td>المصروفات</td>
                                    <td>
                                      <select style="width:180px;" class="small-select recipets-1" name="recipets-2" >
                                        <?php 
                                          $recipets = query("SELECT * FROM payment_vouchers where contract_id = ?",$contract['contract_id']);
                                          foreach($recipets as $recipet)
                                          {
                                            echo "<option value='{$recipet['payment_id']}'>{$recipet['payment_id']}# | {$recipet['amount']} ر.س</option>";
                                          }
                                        ?>
                                        
                                      </select>

                                    </td>
                                    <td>
                                    <a href="#edit_client" class="print_payment"><img src="images/print.png" class="margin-right5" align="" alt="Edit"/></a>
                                    	<!--<a href="#edit_client<?php //echo $contract['contract_id']; ?>" class="edit_client_pop"><img src="images/print.png" class="margin-right5" align="" alt="Edit"/></a>-->
                                       <!-- create pop-up triggerer, Ajax request will be sent to href url -->
                                      <a href="create-pop-ups/payment.php?id=<?php echo $contract['contract_id']; ?>" class="ajax-pop-ups-magnific-no-modal"><img src="images/plus.png" class="margin-right5" align="" alt="Edit"/></a>
                                        
                                    </td>
                                    <td >بدل الايجار</td>
                                    <td class="paid_back"><?php echo $contract['paid_back']; ?></td>
                                </tr>
                                
                                <tr>
                                    <td>الخدمات</td>
                                    <td>
                                     <select  style="width:180px;" class="small-select recipets-1" name="recipets-3" >
                                        <?php 
                                          $services = query("SELECT * FROM service_vouchers where contract_id = ?",$contract['contract_id']);
                                          foreach($services as $recipet)
                                          {
                                            echo "<option value='{$recipet['payment_id']}'>{$recipet['payment_id']}# | {$recipet['amount']} ر.س</option>";
                                          }
                                        ?>
                                        <input id="total_service_revenue" type="hidden" value="<?php echo $contract['services_revenue']; ?>"/>
                                      </select>
                                    </td>
                                    <td>
								
                                    <a href="#edit_client" class="print_service"><img src="images/print.png" class="margin-right5" align="" alt="Edit"/></a>
									<a href="create-pop-ups/service.php?id=<?php echo $contract['contract_id']; ?>" class="ajax-pop-ups-magnific-no-modal"><img src="images/plus.png" class="margin-right5" align="" alt="Edit"/></a>
                                    </td>
                                    <td>التأمين </td>
                                    <td class="insurance"><?php echo $contract['insurance']; ?></td>
                                </tr>
                         </table>
                         
                        </div>
                        
                        <span class="small"></span>
                        <input type="hidden" name="what-button" id="what-button" value='<?php echo $contract['contract_status'] ?>' />
                        <div class="mfp-close close-button white" >x</div>
                        <?php if($contract['contract_status'] == 2)
                        { ?>
                        
                        <div class="check-in  disabled-style left" disabled = "disabled" style="width:120px">دخول check in</div>
                        
                        <div class="check-out disabled-style left margin-left11 "  style="width:120px">خروج check out</div>
                        
                        <?php } if($contract['contract_status'] == 1){ ?>
                        <div class="check-in disabled-style left" style="width:130px">دخول check in</div>
                        <div class="check-out disabled-style left margin-left11" disabled="disabled" style="width:120px">خروج check out</div>
                        <div class="clear"></div>
                        <?php } if($contract['contract_status'] == 3){ ?>
                          <a href="view-pop-ups/fatora.php?id=<?php echo $contract['contract_id']; ?>" class="ajax-pop-ups-magnific-no-modal"><div class="check-in disabled-style left" style="width:130px">عرض الفاتورة</div></a>
                          <a href="view-pop-ups/contract.php?id=<?php echo $contract['contract_id']; ?>" class="ajax-pop-ups-magnific-no-modal"><div class="check-in disabled-style left" style="width:130px">عرض العقد</div></a>
                        <?php } ?>
                        <div class="clear"></div>
                        </div>
                        <div class="clear"></div>
                        </form>
                        </div>
                      </div>